﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;

namespace Convertor
{
    /// <summary>
    /// 模板保存类
    /// </summary>
    [Serializable]
    public class TemplateToSaveContainer : IEquatable<TemplateToSaveContainer>
    {
        private string uniqueId;
        /// <summary>
        /// Template's gloable unique id(Use to track template's origination
        /// </summary>
        public string UniqueId
        {
            get { return uniqueId; }
        }
        private string userId;
        /// <summary>
        /// Set or get template's creator Id
        /// </summary>
        public string UserId
        {
            get { return userId; }
            set { userId = value; }
        }
        private string name;
        /// <summary>
        /// Set or get template's realname
        /// </summary>
        public string Name
        {
            get { return name; }
            set
            {
                name = value; 
                if (String.IsNullOrEmpty(value))
                {
                    throw new ApplicationException("Name is mandatory.");
                }
            }
        }
        private string description;
        /// <summary>
        /// set or get template's description
        /// </summary>
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        private DateTime saveDate;
        /// <summary>
        /// Set or get template's saving date
        /// </summary>
        public DateTime SaveDate
        {
            get { return saveDate; }
            set { saveDate = value; }
        }
        private bool locked;
        /// <summary>
        /// set or get plugin is able to modified
        /// </summary>
        public bool Lock
        {
            get { return locked; }
            set { locked = value; }
        }
        private ObservableCollection<IPluginItem> plugins;
        /// <summary>
        /// Set or get template's plugins
        /// </summary>
        public ObservableCollection<IPluginItem> Plugins
        {
            get { return plugins; }
            set { plugins = value; }
        }
        private string path;
        /// <summary>
        /// Set or get template's path
        /// </summary>
        public string Path
        {
            get { return path; }
            set { path = value; }
        }
        private string inputText;
        /// <summary>
        /// Template's last input content
        /// </summary>
        public string InputText
        {
            get { return inputText; }
            set { inputText = value; }
        }
        private bool selected = true;
        /// <summary>
        /// Not used
        /// </summary>
        public bool Selected
        {
            get { return selected; }
            set { selected = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public TemplateToSaveContainer()
        {
            init();
        }

        private void init()
        {
            plugins = new ObservableCollection<IPluginItem>();
            uniqueId = Guid.NewGuid().ToString();
            name = string.Format("{0}_{1}", UILanguage.FindResource("UnnamedTemplate"), (Config.GlobalConfig.NewTemplateCount++));
            path = System.IO.Path.Combine(Config.GlobalConfig.WorkspacePath, Name + ".cvt1");
        }

        public override string ToString()
        {
            return Name;
        }

        #region IEquatable<PluginsSaveContainer> 成员

        public bool Equals(TemplateToSaveContainer other)
        {
            return this.UniqueId == other.UniqueId;
        }

        #endregion

    }
}
